//
//  PPAlbumPictureCell.m
//  pickpic
//
//  Created by 胡文广 on 2017/5/20.
//  Copyright © 2017年 MicroDream. All rights reserved.
//

#import "PPAlbumPictureCell.h"
#import "PPAlbumPictureEditView.h"
@interface PPAlbumPictureCell()

@property (nonatomic,strong) PPAlbumPictureEditView *editView;
@end
@implementation PPAlbumPictureCell

- (PPAlbumPictureEditView *)editView{

    if (!_editView) {
        _editView = [[PPAlbumPictureEditView alloc] init];
        WEAKSELF;
        _editView.BlockAddPicture = ^{
            if ([weakSelf.delegate respondsToSelector:@selector(addAlbumPicture)]) {
                [weakSelf.delegate addAlbumPicture];
            }
        };
        
        _editView.BlockRemovePicture = ^(PPAbstractArtwork *artwork,NSInteger index){
            if ([weakSelf.delegate respondsToSelector:@selector(removeAlbumPicture: removeIndex:)]) {
                [weakSelf.delegate removeAlbumPicture:artwork removeIndex:index];
            }
        
        };
        _editView.BlockDidSelectPicture = ^(PPAbstractArtwork *artwork,NSInteger index){
            
            if ([weakSelf.delegate respondsToSelector:@selector(didSelectAlbumPicture:selectIndex:)]) {
                [weakSelf.delegate didSelectAlbumPicture:artwork selectIndex:index];
            }
            
        };
    }
    return _editView;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.editView.backgroundColor = CLEAR;
        
        [self addSubview:_editView];
    }
    
    return self;
}

- (void)setPictures:(NSMutableArray *)pictures{

    _pictures = pictures;
    
    
    self.editView.frame = CGRectMake(14, 32,SCREEN_WIDTH - 28,[self justFrame]);

    self.editView.pictures = _pictures;
    
    [self.editView reloadData];
    

    
}
//#define kAppViewH 80 //每个小视图高80
//#define kAppViewW 80 //每个小视图宽80
#define kColCount 4 //每行视图数量一定，都是4个
- (CGFloat )justFrame{
    
    CGFloat marginY = 9;//高度
    CGFloat itemH = (SCREEN_WIDTH -14*2 - 3*marginY)/4;
    //行号
    NSInteger row = (self.pictures.count -1)/kColCount;
    
    return  marginY + row * (itemH + marginY) + itemH - marginY;
}

@end
